import { Injectable, Logger } from "@nestjs/common";
import { SchedulerRegistry } from "@nestjs/schedule";

@Injectable()
export class SchedulerService {

    constructor(private readonly schedulerRegistry: SchedulerRegistry) { }

    getCornJobsInfo(): string[] {
        const cronJobs: string[] = [];
        this.schedulerRegistry.getCronJobs().forEach((job, name) => {
            cronJobs.push(`Cron Job: ${name} - ${job.cronTime} - ${job.lastDate()}`);
            job.stop();
        });
        return cronJobs;
    }

    getTimeoutJobsInfo(): string[] {
        const timeoutJobs: string[] = [];
        this.schedulerRegistry.getIntervals().forEach((job) => {
            timeoutJobs.push(`Timeout Job:  ${job}`);
        });
        return timeoutJobs;
    }

    getIntervalJobsInfo(): string[] {
        const intervalJobs: string[] = [];
        this.schedulerRegistry.getIntervals().forEach((job) => {
            intervalJobs.push(`Interval Job:  ${job}`);
        });
        return intervalJobs;
    }
}